package com.bgi.uims.pub.utils;

import java.security.Security;
import com.sun.crypto.provider.SunJCE;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
/**
 * 
 * ClassName: Encryption <br/>
 * Function: TODO base64字符转换. <br/>
 * Reason: TODO ADD REASON(可选). <br/>
 * date: 2014-10-20 下午02:05:47 <br/>
 *
 * @author fukun
 * @version 
 * @since JDK 1.7
 */
public class Encryption {

    public Encryption() {
    }
    //加密
    public static String getEncrypt(String temp){
        String result = "";
        byte[] data = null;
        Security.addProvider(new SunJCE());
        data = temp.getBytes();
        result = new BASE64Encoder().encode(data);
        return result ;
    }
    //解密
    public static  String getDecrypt(String temp){
        String result = "";
        try {
            byte[] data = new BASE64Decoder().decodeBuffer(temp);
            result = new String(data);
        }
        catch(java.io.IOException e){
            return result;
        }
        return result;
    }
    
    public static void main(String[] arg){
//    	Encryption en = new Encryption();
    	String x = getEncrypt("123");
    	x = getEncrypt(x);
    	System.out.println("123=" + x);
    	String y = getDecrypt("6532dc2eaf81691db2f64145d1e081cf");    
//    	y = getDecrypt(y);  
    	System.out.println("6532dc2eaf81691db2f64145d1e081cf=" + y);
    }

}
